package com.atguigu.statistics.schedule;

import com.atguigu.statistics.service.DailyService;
import com.atguigu.statistics.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduleTask {

    @Autowired
    private DailyService dailyService;

//    @Scheduled(cron = "0/5 * * * * ?") //每隔五秒执行一次方法
//    public void task() {
//        System.out.println("task任务被执行了.........");
//    }

    /**
     * 在每天凌晨1点，把前一天的数据进行数据查询添加
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void StaTask() {
        dailyService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }
}
